const { list } = require('./src/mock')
const bodyParser = require('body-parser')
module.exports = {
  devServer: {
    before(app) {
      // 处理 post 请求
      app.use(bodyParser.json())
      // 分页接口
      app.get('/api/list', (req, res) => {
        const { pageIndex, pageSize } = req.query;
        res.send({
          code: 200,
          data: list.slice(pageIndex * pageSize, (+pageIndex + 1) * pageSize)
        })
      })

      // 详情接口
      app.post('/api/detail', (req, res) => {
        const { id } = req.body
        // 通过id 找数据
        const item = list.find(item => item.id === id)
        res.send({
          code: 200,
          data: item
        })
      })
      }
  }
}